/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tp_sd_server.model;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 *
 * @author Tiago
 */
public class MessageLog {

    private static MessageLog instance = new MessageLog();

    public static MessageLog getInstance() {
        return instance;
    }


    public interface IMessageListener{
        public void onAddMessage(String string);
    }

    private ArrayList<String> messages = new ArrayList<String>();
    private IMessageListener listener;



    private  MessageLog() {}


    public void addMessage(String message) {

        DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
        String date = df.format(new Date());
        String msg = date + ": " + message;

        messages.add(msg);
        if(listener!=null){
            listener.onAddMessage(msg);
        }
        System.out.println(msg);
        
    }

    public void setListener(IMessageListener listener) {
        this.listener = listener;
    }
    

    List<String> getMessageList() {
        return messages;
    }

}
